#include <bits/stdc++.h>
using namespace std;
int read();
int t,n,x,a[1000005],ma=-1;
long long s=0;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	t=read();
	while(t--){
		s=0;ma=-1;
		n=read();
		for(int i=1;i<=1000004;i++)a[i]=0;
		while(n--){
			x=read();
			a[x]++;
			ma=max(ma,x);
		}
		for(int i=1;i<=ma;i++){
			if(a[i]>1)s+=i*(a[i]-1);
		}
		cout<<s<<endl;
	}
	return 0;
}
int read(){
	int x=0,f=1;char c;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c^48);
	while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}
